/**
 * @program: LeetCode
 * @description: LeetCode : 680. 验证回文串 II
 * @author: WXY
 * @create: 2023-01-03 16:49
 * @Version 1.0
 **/
public class Num680_validPalindrome {
    public boolean validPalindrome(String s) {
        int l = 0;
        int r = s.length();
        while (l < r) {
            if (s.charAt(l) != s.charAt(r)) {
                return isVaild(s, l + 1, r) || isVaild(s, l, r - 1);
            }
            l++;
            r--;
        }
        return true;
    }

    private boolean isVaild(String s, int l, int r) {
        while (l < r) {
            if (s.charAt(l) != s.charAt(r)) {
                return false;
            }
            l++;
            r--;
        }
        return true;
    }
}
